﻿using System.Collections.Generic;

public class MsgCenter : IMsgCenter
{
	private Queue<RecData> reqQueue = new Queue<RecData>();

	private int headLength;

	public MsgCenter()
	{
		headLength = ConstantDef.headLength;
	}

	public void EnMsg(RecData data)
	{
		reqQueue.Enqueue(data);
	}

	public void ProcessQueue()
	{
		if (reqQueue.Count > 0)
		{
			RecData data = reqQueue.Dequeue();

			if (handlerDic.ContainsKey(data.ID))
			{
				IMsgHandler handler = handlerDic[data.ID];
				handler.Handle(data);
			}
			else
			{
				MyLog.LogError("Method Not Regist : " + data.ID);
			}

		}
	}

	private Dictionary<int, IMsgHandler> handlerDic = new Dictionary<int, IMsgHandler>();

	public void Regist(int id, IMsgHandler handler)
	{
		if (!handlerDic.ContainsKey(id))
		{
			handlerDic.Add(id, handler);
		}
	}
}
